﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SHKF.B2C.BaseHosted;
using SHKF.B2C.BLL.Center;
using SHKF.B2C.Model.Dto;
using SHKF.B2C.Model.Dto.Center;
using SHKF.B2C.Model.Entity.Center;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SHKF.B2C.Mannage.Service.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class ErpServerController : BaseController
    {
        private readonly ErpServerBLL erpServerBLL;

        public ErpServerController(ErpServerBLL erpServerBLL, 
            ILogger<ErpServerController> logger) :base(logger)
        {
            this.erpServerBLL = erpServerBLL;
        }

        [HttpGet("list")]
        public ErpServerListDto List()
        {
            ErpServerListDto dto = new ErpServerListDto();
            try
            { 
                List<ErpServerEntity> list = this.erpServerBLL.QueryServer();
                dto.data = list;
              
            }
            catch (Exception ex)
            {
                dto.error = new Error() { code = -1, msg = ex.Message };
            }
            return dto;
        }

        [HttpPost("Save")]
        public DataDto Save(ErpServerEntity data)
        {
            DataDto dto = new DataDto();

            try
            {
                this.erpServerBLL.SaveServer(data);
            }
            catch (Exception ex)
            {
                dto.error = new Error() { code = -1, msg = ex.Message };
            }
            return dto; 
        }
    }
}
